#include "Gameplay.h"
#include "RessourceManager.h"
#include "Shader.h"
#include "CarHuman.h"
#include "VehiculeGraphicBlur.h"

namespace PM3D
{
    VehiculeGraphicBlur::VehiculeGraphicBlur(const std::wstring& nomFichier, Dispositif* d3dDevice, float blurSize)
        :VehiculeGraphic(nomFichier, d3dDevice),blurSize_(blurSize)
    {
    }

    VehiculeGraphicBlur::~VehiculeGraphicBlur()
    {
    }

    void VehiculeGraphicBlur::createEffect()
    {
        RessourceManager<Shader>& shaderManager = RessourceManager<Shader>::getInstance();
        shader_ = shaderManager.getNewRessource(L"VehiculeShaderBlur.fx", device_);
        effectFX_ = shader_->getD3DEffect();

        // Setting des handle
        techniqueFX_= effectFX_->GetTechniqueByName("ObjetTech");
        matWVP_FX_ = effectFX_->GetParameterByName(0, "matWVP");
        matWorldFX_ = effectFX_->GetParameterByName(0, "matWorld");
        speed_ = effectFX_->GetParameterByName(0, "speed");

        eyePosFX_ = effectFX_->GetParameterByName(0, "eyePos");
        colorTextureFX_ = effectFX_->GetParameterByName(0, "ColorTexture");

        directionalLightFX_ = effectFX_->GetParameterByName(0, 
            "dirLight");
        pointLight1FX_ = effectFX_->GetParameterByName(0,
            "pointLight1");
        pointLight2FX_ = effectFX_->GetParameterByName(0,
            "pointLight2");
        pointLight3FX_ = effectFX_->GetParameterByName(0,
            "pointLight3");
    }

    void VehiculeGraphicBlur::draw()
    {
        float speed = GAMEPLAY::Gameplay::getInstance().getNitroTimeLeft();
        if (speed > 0.0f)
        {
            D3DXVECTOR3 linearSpeed = physicCar_->getLinearVelocity()/100.0f;
            linearSpeed.z=0.0f;
            translate(-speed*linearSpeed);
            VehiculeGraphic::draw();
            translate(speed*0.25f*linearSpeed);
            VehiculeGraphic::draw();
            translate(speed*0.25f*linearSpeed);
            VehiculeGraphic::draw();
            translate(speed*0.25f*linearSpeed);
            VehiculeGraphic::draw();
            translate(speed*0.25f*linearSpeed);
            VehiculeGraphic::draw();
        }
        else
            VehiculeGraphic::draw();
    }
} // fin namespace PM3D
